﻿@using KPIS.GERP.Models.ICM
@model Asset

@{
    var service = new KPIS.GERP.WEB.GIMS.AssetService.AssetServiceClient();
    var service2 = new KPIS.GERP.WEB.GIMS.IcmMasLookUpService.IcmMasLookUpServiceClient();
    var db = new GERPContext(true);

    ViewData["CurrentPrice"] = service.GetCurrentPrice(ViewBag.AssetId);
    
    var whIds = db.Warehouses.Where(o => o.RecordStatus != "D").Select(o => new SelectListItem { Text = o.Name, Value = o.WhId.ToString() }).ToList();
    
    var depType = db.MasDepreciationTypes.Where(o => o.RecordStatus != "D" || o.DpTypeId == Model.DepreciationTypeId);
    if (Model.MasDepreciationType == null) { Model.MasDepreciationType = depType.FirstOrDefault(); }
    
    var masDepreciationTypes = depType.Select(o => new SelectListItem {Text =  o.Name,Value = o.DpTypeId.ToString()}).ToList();
    
    var assetStatuses = service2.MasLookUpSelectList(IcmMasLookUpType.LookUpType.AssetStatus)
        .Where(s => (Model.AssetStatusId == 57 && (s.Text == "ใช้งานได้" || s.Text == "ชำรุด")) ||
                    (Model.AssetStatusId == 58 && (s.Text == "ชำรุด")) ||
                    ((s.Text == "ไม่มีข้อมูล"))).ToList();
                    
    var units = db.MasUnits.Where(o => o.RecordStatus != "D").Select(o => new SelectListItem {Text = o.Name, Value = o.UnitId.ToString()});
    
    var assetStatus = assetStatuses.FirstOrDefault(o => o.Value == Model.AssetStatusId.ToString());
    if (assetStatus != null) { assetStatus.Selected = true; }

    var masResourceTypes = db.MasResourceTypes.Where(o => o.RecordStatus != "D")
        .Select(o => new SelectListItem {Text = o.Name, Value = o.ResTypeId.ToString(), Selected = Model.AssetTypeId == o.ResTypeId});
        
    var masResourceGroups = db.MasResourceGroups.Where(o => o.RecordStatus != "D")
        .Select(o => new SelectListItem { Text = o.Name, Value = o.ResGrpId.ToString(), Selected = Model.ResGrpId == o.ResGrpId });
        
    var masResourceSubGroups = db.MasResourceSubGroups.Where(o => o.RecordStatus != "D")
        .Select(o => new SelectListItem { Text = o.Name, Value = o.ResSubGrpId.ToString(), Selected = Model.ResSubGrpId == o.ResSubGrpId });
        
    var masResourceItems = db.MasResourceItems.Where(o => o.ResItemId == Model.ResItemId).Select(o => new SelectListItem
    {
        Text = ("[" + o.Code + "] " + o.Name  + " - " + o.MasResourceSubGroup.MasResourceGroup.MasResourceType.Name + " / " + 
            o.MasResourceSubGroup.MasResourceGroup.Name + " / " + o.MasResourceSubGroup.Name) ,
        Value = o.ResItemId.ToString(),
        Selected = Model.ResItemId == o.ResItemId
    });
}

@if (ViewContext.RouteData.Values["action"].ToString().ToLower() == "assetdetails")
{
    @Html.HiddenFor(model => model.AssetId, new { @value = ViewBag.AssetId })
}

<div class="widget-box">
    
    @if (!string.IsNullOrWhiteSpace(ViewBag.statusMessage as string))
    {
        <div class="row-fluid">
            <div class="alert alert-block alert-success">
                <button type="button" class="close" data-dismiss="alert">
                    <i class="icon-remove"></i>
                </button>
                <i class="icon-ok green"></i>
                @if (ViewBag.statusMessage as string == "1")
                {
                    @:บันทึกข้อมูลสำเร็จ
                }else if (ViewBag.statusMessage as string == "2")
                {
                    @:ลบข้อมูลสำเร็จ
                }
            </div>
        </div>
    } 
    
    <div class="widget-header"><h4>@Model.AssetCode - @Model.AssetName</h4></div>

    <div class="widget-body">
        <div class="widget-body-inner">
            <div class="widget-main">
                <div style="width: 900px;">
                    <div class="controls-field-from-right" style="float: left; width: 500px;">
                        @if (Model.RecordStatus == "D")
                        {
                            <div class="control-group">
                                <div class="control-label">
                                    สถานะรายการ :
                                </div>
                                <div class="controls" style="color:red;font-weight: bold;">
                                     ถูกลบ
                                </div>
                            </div>
                        }
                        <div class="control-group">
                            <div class="control-label">
                                รหัสสินทรัพย์ :
                            </div>
                            <div class="controls">
                                @Html.TextBoxFor(model => model.AssetCode, new { maxlength = 23})
                            </div>
                        </div>
                        <div class="control-group">
                            <div class="control-label">
                                ชื่อสินทรัพย์ :
                            </div>
                            <div class="controls">
                                @Html.TextBoxFor(model => model.AssetName, new { style = "width:420px;" })
                            </div>
                        </div>
                        <div class="control-group">
                            <div class="control-label">
                                หมายเลขเครื่อง :
                            </div>
                            <div class="controls">
                                @Html.TextBoxFor(model => model.SerialNumber)
                            </div>
                        </div>
                        <div class="control-group">
                            <div >
                                <div class="controls-field-from-right" style="float: left; width: 400px;">
                                    <div class="control-label">
                                        ประเภทสินทรัพย์ :
                                    </div>
                                    <div class="controls">
                                        @Html.DropDownListFor(m => m.AssetTypeId, masResourceTypes, new { @class = "chzn-select input-xlarge" })
                                    </div>
                                </div>
                                <div class="controls-field-from-left" style="float: left; width: 400px;">
                                    <div class="control-label">
                                        ครุภัณฑ์ต่ำกว่าเกณฑ์ :
                                    </div>
                                    <div class="controls">
                                        <input type="checkbox" name="IsLowerAsset" id="IsLowerAsset" value="true"
                                            @(Model.IsLowerAsset == true ? "checked=\"checked\"" : "") />
                                        <span class="lbl"></span>
                                    </div>
                                </div>
                                <div class="clear" style="clear: both; width: 0px; height: 0px;"></div>
                            </div>
                        </div>
                        <div class="control-group">
                            <div class="control-label">
                                หมวดสินทรัพย์ :
                            </div>
                            <div class="controls">
                                @Html.DropDownListFor(model => model.ResGrpId, masResourceGroups, new {  @class = "chzn-select input-xlarge" })
                            </div>
                        </div>
                        <div class="control-group">
                            <div class="control-label">
                                กลุ่มสินทรัพย์ :
                            </div>
                            <div class="controls">
                                @Html.DropDownListFor(model => model.ResSubGrpId, masResourceSubGroups, new {  @class = "chzn-select input-xlarge" })
                            </div>
                        </div>
                    </div>
                    <div class="controls-field-from-left" style="float: left; width: 400px;">
                        <div class="control-group">
                            <div class="controls">
                                <div>
                                    @Html.HiddenFor(model => model.PicturePath)
                                    @if (Model.PicturePath == null)
                                    {
                                        <img class="imgBorder" src="~/Content/Images/Icon/no_image.png" />
                                    }
                                    else
                                    {
                                        <a class="cboxElement" data-rel="colorbox" title="Photo"
                                           href="~/Content/Ace/assets/Asset/@Model.PicturePath">
                                            <img class="imgBorder" src="~/Content/Ace/assets/Asset/@Model.PicturePath" />
                                        </a>
                                    }
                                </div>
                                @Html.ValidationMessageFor(model => model.PicturePath)
                                <div style="margin: 8px auto auto 20px;">
                                    <input type="file" name="file" id="file" value="@Model.PicturePath" />
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="clear" style="clear: both; width: 0px; height: 0px;"></div>
                </div>
                <div class="control-group">
                    <div class="control-group">
                        <div class="control-label">
                            ชนิดสินทรัพย์ :
                        </div>
                        <div class="controls">
                            @Html.DropDownListFor(m => m.ResItemId, masResourceItems, 
                                new { data_manualwidth = "70%", @class = "chzn-select input-xlarge" })
                            <a onclick="javascript: reloadDropdown();" style="cursor: pointer">โหลดพัสดุ</a> | 
                            <a onclick="javascript: window.open('@Url.Action("Details", "MasResourceItem")/' + $('#ResItemId').val(), '_blank');" style="cursor: pointer">ดูพัสดุ</a>
                             
                        </div>
                    </div>
                    <div >
                        <div class="controls-field-from-right" style="float: left; width: 400px;">
                            <div class="control-label">
                                จำนวน :
                            </div>
                            <div class="controls">
                                @Html.TextBoxFor(model => model.Quantity, new { disabled = "disabled", style = "text-align:center" })
                            </div>
                        </div>
                        <div class="controls-field-from-left" style="float: left; width: 400px;">
                            <div class="control-label">
                                หน่วย :
                            </div>
                            <div class="controls">
                                @Html.DropDownListFor(model => model.UnitId, units)
                            </div>
                        </div>
                        <div class="clear" style="clear: both; width: 0px; height: 0px;"></div>
                    </div>
                </div>
                <div class="control-group">
                    <div >
                        <div class="controls-field-from-right" style="float: left; width: 400px;">
                            <div class="control-label">
                                ราคาต่อหน่วย :
                            </div>
                            <div class="controls">
                                <table>
                                    <tr>
                                        <td>
                                            @Html.TextBoxFor(model => model.Price, new { style = "text-align:right" })
                                        </td>
                                        <td>
                                            บาท
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </div>

                        <div class="controls-field-from-right" style="float: left; width: 400px;">
                            <div class="control-label">
                                ใช้งานอยู่ที่ :
                            </div>
                            <div class="controls">
                                @Html.DropDownListFor(model => model.WhId, whIds)
                            </div>
                        </div>
                        <div class="clear" style="clear: both; width: 0px; height: 0px;"></div>
                    </div>
                </div>
                
                <div class="control-group">
                    <div>
                        <div class="controls-field-from-right" style="float: left; width: 400px;">
                            <div class="control-label">
                                ชื่อเจ้าหน้าที่ :
                            </div>
                            <div class="controls"> 
                                 @Html.TextBoxFor(model => model.Place )
                                         
                            </div>
                        </div>
                         
                        <div class="clear" style="clear: both; width: 0px; height: 0px;"></div>
                    </div>
                </div>

                <div class="control-group">
                    <div class="control-label">
                        ราคาปัจจุบัน :
                    </div>
                    <div class="controls">
                        <table>
                            <tr>
                                <td>
                                    @Html.TextBox("txtCurrentPrice", ViewData["CurrentPrice"], new { disabled = "disabled", style = "text-align:right" })
                                </td>
                                <td>
                                    บาท
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
                <div class="control-group">
                    <div class="control-label">
                        รายละเอียด :
                    </div>
                    <div class="controls">
                        @Html.TextAreaFor(model => model.Description, new { style = "width:750px; height: 90px;" })
                    </div>
                </div>
                <div class="control-group">
                    <div >
                        <div class="controls-field-from-right" style="float: left; width: 400px;">
                            <div class="control-label">
                                สถานะการใช้งาน :
                            </div>
                            <div class="controls">
                                @Html.DropDownListFor(m => m.AssetStatusId, assetStatuses)
                            </div>
                        </div>

                        <div class="controls-field-from-right" style="float: left; width: 400px;">
                            <div class="control-label">
                                วันที่หมดอายุประกัน :
                            </div>
                            <div class="controls">
                                <span class="input-icon input-icon-right">
                                    <input class="date-picker" data-date-language="th-th"
                                           data-provide="datepicker" id="QualityAssuranceExpireDate" name="QualityAssuranceExpireDate"
                                           placeholder="วันที่ทำรายการ" type="text" value="@Model.QualityAssuranceExpireDate">
                                    <i class="icon-calendar"></i>
                                </span>
                            </div>
                        </div>
                        <div class="clear" style="clear: both; width: 0px; height: 0px;"></div>
                    </div>
                </div>
                <div class="control-group">
                    <div >
                        <div class="controls-field-from-right" style="float: left; width: 400px;">
                            <div class="control-label" title="@Html.DisplayFor(m=>m.MasDepreciationType.Name)">
                                ประเภทค่าเสื่อม :
                            </div>
                            <div class="controls">
                                @Html.DropDownListFor(model => model.DepreciationTypeId, masDepreciationTypes)
                            </div>
                        </div>

                        <div class="controls-field-from-right" style="float: left; width: 400px;">
                            <div class="control-label">
                                อัตราค่าเสื่อมต่อปี :
                            </div>
                            <div class="controls">
                                @Html.TextBoxFor(model => model.MasDepreciationType.DpRateYear, new { disabled = "disabled",style = "text-align:center" } )
                            </div>
                        </div>
                        <div class="clear" style="clear: both; width: 0px; height: 0px;"></div>
                    </div>
                </div>

                <hr />

                <div class="control-group">
                    <div class="control-label">
                        โครงการ :
                    </div>
                    <div class="controls">
                        @Html.TextBoxFor(model => model.ProjectExpense.Project.Name, new { disabled = "disabled", style = "width:600px;" })
                    </div>
                </div>
                <div class="control-group">
                    <div >
                        <div class="controls-field-from-right" style="float: left; width: 400px;">
                            <div class="control-label">
                                ประเภทแหล่งเงิน :
                            </div>
                            <div class="controls">
                                @Html.TextBoxFor(model => model.ProjectExpense.MasBudgetSource.Name, new { disabled = "disabled" })
                            </div>
                        </div>

                        <div class="controls-field-from-right" style="float: left; width: 400px;">
                            <div class="control-label">
                                ประเภทงบ :
                            </div>
                            <div class="controls">
                                @Html.TextBoxFor(model => model.ProjectExpense.MasBudgetExpense.MasBudgetExpenseGroup.Name, new { disabled = "disabled" })
                            </div>
                        </div>
                        <div class="clear" style="clear: both; width: 0px; height: 0px;"></div>
                    </div>
                </div>
                <div class="control-group">
                    <div >
                        <div class="controls-field-from-right" style="float: left; width: 400px;">
                            <div class="control-label">
                                วิธีการรับเข้า :
                            </div>
                            <div class="controls">
                                @Html.TextBoxFor(model => model.ReceiveDtl.Received.ReceiveType.LookUpName, new { disabled = "disabled" })
                            </div>
                        </div>
                        <div class="controls-field-from-right" style="float: left; width: 400px;">
                            <div class="control-label">
                                วันที่ขึ้นทะเบียนสินทรัพย์ :
                            </div>
                            <div class="controls"> 
                                <span class="input-icon input-icon-right">
                                    <input class="date-picker" data-date-language="th-th"
                                           data-provide="datepicker" id="AssetDate" name="AssetDate"
                                           placeholder="วันที่ทำรายการ" type="text" value="@Model.AssetDate">
                                    <i class="icon-calendar"></i>
                                </span>
                            </div>
                        </div>
                        <div class="clear" style="clear: both; width: 0px; height: 0px;"></div>
                    </div>
                </div>
                <div class="control-group">
                    <div class="control-label">
                        หมายเหตุ :
                    </div>
                    <div class="controls">
                        @Html.TextAreaFor(model => model.Remark, new { style = "width:750px; height: 90px;" })
                    </div>
                </div>
                <div class="control-group" style="margin-left: 180px; display:none;">
                    <div >
                        <div class="controls-field-from-right" style="float: left; width: 200px;">
                            @Html.ActionLink("ดูรายละเอียดค่าเสื่อมราคา", null, null
                                , new { @class = "btn btn-gray button-standard-width btn-small", role = "button" })
                        </div>
                        <div class="controls-field-from-right" style="float: left; width: 200px;">
                            @Html.ActionLink("ดูรายละเอียดการประกันภัย", null, null
                                , new { @class = "btn btn-gray button-standard-width btn-small", role = "button" })
                        </div>
                        <div class="controls-field-from-right" style="float: left; width: 200px;">
                            @Html.ActionLink("ดูประวัติการเคลื่อนไหว", null, null
                                , new { @class = "btn btn-gray button-standard-width btn-small", role = "button" })
                        </div>
                        <div class="controls-field-from-right" style="float: left; width: 200px;">
                            @Html.ActionLink("ดูประวัติการซ่อม", null, null
                                , new { @class = "btn btn-gray button-standard-width btn-small", role = "button" })
                        </div>
                        <div class="clear" style="clear: both; width: 0px; height: 0px;"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>